/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Jirka
 */
@Entity
@Table(name = "game")
@NamedQueries({@NamedQuery(name = "Game.findAll", query = "SELECT g FROM Game g"), @NamedQuery(name = "Game.findByDatum", query = "SELECT g FROM Game g WHERE g.datum = :datum"), @NamedQuery(name = "Game.findByMatchId", query = "SELECT g FROM Game g WHERE g.matchId = :matchId")})
public class Game implements Serializable {
    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @Column(name = "datum")
    @Temporal(TemporalType.DATE)
    private Date datum;
    @Id
    @Basic(optional = false)
    @Column(name = "match_id")
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    private Integer matchId;
    @JoinColumn(name = "away_club_id", referencedColumnName = "club_id")
    @ManyToOne(optional = false)
    private Club awayClub;
    @JoinColumn(name = "home_club_id", referencedColumnName = "club_id")
    @ManyToOne(optional = false)
    private Club homeClub;
    @JoinColumn(name = "league_id", referencedColumnName = "league_id")
    @ManyToOne
    private League league;
    @OneToMany(mappedBy = "match")
    private Collection<Event> eventCollection;

    public Game() {
    }

    public Game(Integer matchId) {
        this.matchId = matchId;
    }

    public Game(Integer matchId, Date datum) {
        this.matchId = matchId;
        this.datum = datum;
    }

    public Date getDatum() {
        return datum;
    }

    public void setDatum(Date datum) {
        this.datum = datum;
    }

    public Integer getMatchId() {
        return matchId;
    }

    public void setMatchId(Integer matchId) {
        this.matchId = matchId;
    }

    public Club getAwayClub() {
        return awayClub;
    }

    public void setAwayClub(Club awayClub) {
        this.awayClub = awayClub;
    }

    public Club getHomeClub() {
        return homeClub;
    }

    public void setHomeClub(Club homeClub) {
        this.homeClub = homeClub;
    }

    public League getLeague() {
        return league;
    }

    public void setLeague(League league) {
        this.league = league;
    }

    public Collection<Event> getEventCollection() {
        return eventCollection;
    }

    public void setEventCollection(Collection<Event> eventCollection) {
        this.eventCollection = eventCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (matchId != null ? matchId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Game)) {
            return false;
        }
        Game other = (Game) object;
        if ((this.matchId == null && other.matchId != null) || (this.matchId != null && !this.matchId.equals(other.matchId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Game[matchId=" + matchId + "]";
    }

}
